package io.polly.config;

import com.dtp.common.em.QueueTypeEnum;
import com.dtp.common.em.RejectedTypeEnum;
import com.dtp.core.support.ThreadPoolCreator;
import com.dtp.core.thread.DtpExecutor;
import com.dtp.core.thread.ThreadPoolBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author ldz
 * @version V1.0
 * @title: DtpConfig
 * @description: TODO(用一句话描述该文件做什么)
 * @date: 2022/3/17 11:28
 */
@Configuration
public class DtpConfig {

    @Bean
    public DtpExecutor demo1Executor() {
        return ThreadPoolCreator.createDynamicFast("demo1-executor");
    }

    @Bean
    public ThreadPoolExecutor demo2Executor() {
        return ThreadPoolBuilder.newBuilder()
                .threadPoolName("demo2-executor")
                .corePoolSize(8)
                .maximumPoolSize(16)
                .keepAliveTime(50)
                .allowCoreThreadTimeOut(true)
                .workQueue(QueueTypeEnum.SYNCHRONOUS_QUEUE.getName(), null, false)
                .rejectedExecutionHandler(RejectedTypeEnum.CALLER_RUNS_POLICY.getName())
                .buildDynamic();
    }
}
